<template>
  <el-dialog
    title="成单记录"
    :visible.sync="value"
    width="600px"
    :before-close="beforeClose"
  >
    <el-table :data="dataList">
      <el-table-column type="index" width="50"> </el-table-column>
      <el-table-column
        align="center"
        prop="contractCreateTime"
        label="拜访时间"
        min-width="90"
      >
        <template slot-scope="{ row }">
          <span>{{ parseTime(row.contractCreateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="contractType"
        label="成单类型"
        min-width="90"
      >
        <template slot-scope="{ row }">
          {{
            contractTypeDict.find((it) => it.value === row.contractType)
              ? contractTypeDict.find((it) => it.value === row.contractType)
                  .label
              : ''
          }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="contractRemark"
        label="备注"
      ></el-table-column>
    </el-table>
  </el-dialog>
</template>
<script>
import { listContractRecord, manageListContractRecord } from '@/api/enterprise'
export default {
  props: {
    value: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default: () => null
    }
  },
  watch: {
    row(row) {
      if (row) {
        this.getList()
      }
    }
  },
  computed: {
    roles() {
      return this.$store.getters.roles
    },
    contractTypeDict() {
      const dict = this.$store.getters.dict
      const list = []
      for (let value in dict.contractType) {
        list.push({
          label: dict.contractType[value],
          value
        })
      }
      return list
    }
  },
  data() {
    return {
      dataList: [],
      pageNum: 1,
      pageSize: 10
    }
  },
  methods: {
    getList() {
      let fn = listContractRecord
      if (this.roles[0].authority === 'ROLE_ADMIN') {
        fn = manageListContractRecord
      }
      let params = {
        unitOrgCode: this.row.unitOrgCode
      }
      fn({
        ...params,
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }).then((res) => {
        this.dataList = res.data.list
      })
    },
    beforeClose() {
      this.$emit('input', false)
    }
  }
}
</script>
<style lang="scss" scoped>
</style>